package com.devbobcorn.nekoration.client.rendering.entities;

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;

import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.entity.model.ElytraModel;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.Items;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public class ElectroElytraRenderer {
    private final ElytraModel<AbstractClientPlayerEntity> elytraModel = new ElytraModel<>();
    private final EntityModel<AbstractClientPlayerEntity> parent;

    public ElectroElytraRenderer(EntityModel<AbstractClientPlayerEntity> parent){
        this.parent = parent;
    }

    public void render(MatrixStack stack, IRenderTypeBuffer buffers, int packedLight, AbstractClientPlayerEntity player, float a, float b, float partialTicks, float c, float d, float e) {
        if (player.getItemBySlot(EquipmentSlotType.CHEST).getItem() == Items.ELYTRA) {
            stack.pushPose();
            stack.translate(0.0D, 0.0D, 0.125D);
            this.parent.copyPropertiesTo(this.elytraModel);
            this.elytraModel.setupAnim(player, a, b, c, d, e);
            IVertexBuilder ivertexbuilder = buffers.getBuffer(ElectroRenderer.getRenderType(((float)player.tickCount + partialTicks) * 0.02F));
            this.elytraModel.renderToBuffer(stack, ivertexbuilder, packedLight, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
            stack.popPose();
        }
    }
}
